// nodal_support.cpp: implementation of the attributes class.
//
//////////////////////////////////////////////////////////////////////


#include <stdio.h>
#include <string.h>

#include "nodal_support.h"
#include "../draw.h"



//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
// acmF_NodalSupport
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////

// acmF_NodalSupport
//////////////////////////////////////////////////////////////////////
acmF_NodalSupport::acmF_NodalSupport (void)
{
}

// acmF_NodalSupport
//////////////////////////////////////////////////////////////////////
acmF_NodalSupport::~acmF_NodalSupport (void)
{
}


// acmF_NodalSupport::Read
//////////////////////////////////////////////////////////////////////
void acmF_NodalSupport::Read (FILE *ptr_file)
{
  fscanf(ptr_file, "%d %d %d", &sup[0], &sup[1], &sup[2]);
  fscanf(ptr_file, "%d %d %d", &sup[3], &sup[4], &sup[5]);
}


// acmF_NodalSupport::Save
//////////////////////////////////////////////////////////////////////
void acmF_NodalSupport::Save (FILE *ptr_file)
{
  fprintf(ptr_file, "%d %d %d ", sup[0], sup[1], sup[2]);
  fprintf(ptr_file, "%d %d %d", sup[3], sup[4], sup[5]);
}

// acmF_NodalSupport::SetParam
//////////////////////////////////////////////////////////////////////
void acmF_NodalSupport::SetParam (double *param)
{
  sup[0] = int (param[0]);
  sup[1] = int (param[1]);
  sup[2] = int (param[2]);
  sup[3] = int (param[3]);
  sup[4] = int (param[4]);
  sup[5] = int (param[5]);
}

// acmF_NodalSupport::GetParam
//////////////////////////////////////////////////////////////////////
void acmF_NodalSupport::GetParam (int *np, double **param)
{
  *np = 6;

  *param = new double [6];

  (*param)[0] = sup[0];
  (*param)[1] = sup[1];
  (*param)[2] = sup[2];
  (*param)[3] = sup[3];
  (*param)[4] = sup[4];
  (*param)[5] = sup[5];
}

// acmF_NodalSupport::Copy
//////////////////////////////////////////////////////////////////////
acmF_Attribute *acmF_NodalSupport::Copy (void)
{
  double *param;
  int    num_par;
  acmF_CurveSupport *copyatt = new acmF_CurveSupport;

  GetParam (&num_par, &param);
  copyatt->SetParam (param);
  strcpy (copyatt->AttName, AttName);
  return (copyatt);
}

//
//////////////////////////////////////////////////////////////////////////
void acmF_NodalSupport::Draw(int n, double *p)
{
  if (m_pDrawObj == NULL)
    return;

  int type;
  double angle;

  // set type of support
  if (sup[0] == 1 && sup[1] == 0)
  {
    type = 1; angle = 3.1416/2.0;
  }
  else if (sup[0] == 0 && sup[1] == 1)
  {
    type = 1; angle = 0.0;
  }
  else if (sup[0] == 1 && sup[1] == 1)
  {
    type = 2; angle = 0.0;
  }
  else if (sup[0] == 1 && sup[1] == 1 && sup[3] == 1)
  {
    type = 3; angle = 0.0;
  }

  // in case of angle is passed
  if (n == 2)
    angle = p[2];

  double size = m_pDrawObj->ref_size * DSP_SUPPORT_FAC;

  switch (type)
  {
  case 1 : drawSupport1 (p, size, angle );
    break;
  case 2 : drawSupport2 (p, size, angle );
    break;
  case 3 : drawSupport3 (p, size, angle );
    break;
  }
}